***********************************************************
*                                                         *
* How Party Platforms on Immigration become Policy        * 
*                                                         *
* Tobias Böhmelt and Lawrence Ezrow                       *
*                                                         *
* University of Essex                                     *
*                                                         *
* Address Correspondance to: tbohmelt@essex.ac.uk         *
*                                                         *
* This Version: December 30, 2020                         *                   
*                                                         *
***********************************************************

use "C:\Users\tbohmelt\Dropbox\Party to Policy Implementation\Final Data\JPP.dta", clear

*****************************************
* Data Setup and Descriptive Statistics *
*****************************************

gen lnpop=ln(sp_pop_totl)
gen lngdppc=ln(ny_gdp_pcap_cd)
gen ln_migration=ln(i_sm_pop_totl)

xtline DEMIG_count, i(cname) t(year) scheme(plotplain) aspectratio(1) recast(scatter) 
sum DEMIG_count l.DEMIG_count csaliency_avg AvgS_ImmPol nomgdpgr polconiii lnpop lngdppc ln_migration sl_uem_totl_zs if csaliency_avg!=.

***************
* Main Models *
***************

nbreg DEMIG_count l.DEMIG_count csaliency_avg i.ccode i.year, cluster(ccode)
nbreg DEMIG_count l.DEMIG_count polconiii lnpop lngdppc ln_migration sl_uem_totl_zs i.ccode i.year if e(sample), cluster(ccode)
nbreg DEMIG_count l.DEMIG_count csaliency_avg polconiii lnpop lngdppc ln_migration sl_uem_totl_zs i.ccode i.year, cluster(ccode)

preserve
generate where = 0
generate pipe = "|"
reg DEMIG_count l.DEMIG_count csaliency_avg polconiii lnpop lngdppc ln_migration sl_uem_totl_zs i.ccode i.year, cluster(ccode)
keep if e(sample)
qui margins, at(csaliency_avg=(0(1)16)) atmeans
marginsplot, level(90) recast(line) recastci(rline) ci1opts(lp(-) lc(black)) name(graph1, replace) addplot (scatter where csaliency_avg, xlabel(0(2)16) ms(none) blcolor(gray) mlabel(pipe) mlabpos(0)) legend(off) scheme(plotplain) aspectratio(1) title("") xtitle(Immigration Salience) ytitle(Predicted Number of Immigration Policies)
drop pipe where
restore

nbreg DEMIG_count l.DEMIG_count c.csaliency_avg##c.AvgS_ImmPol polconiii lnpop lngdppc ln_migration sl_uem_totl_zs i.ccode i.year, cluster(ccode)

preserve
generate where = -2.5
generate pipe = "|"
reg DEMIG_count l.DEMIG_count c.csaliency_avg##c.AvgS_ImmPol polconiii lnpop lngdppc ln_migration sl_uem_totl_zs i.ccode i.year, cluster(ccode)
keep if e(sample)
qui margins, dydx(csaliency_avg) at(AvgS_ImmPol=(0.3(0.05)0.55)) atmeans
marginsplot, level(90) recast(line) recastci(rline) ci1opts(lp(-) lc(black)) name(graph2, replace) addplot (scatter where AvgS_ImmPol, xlabel(0.3(0.05)0.55) ms(none) blcolor(gray) mlabel(pipe) mlabpos(0)) legend(off) scheme(plotplain) aspectratio(1) title("") xtitle(Migration Policy Restrictions) ytitle(Marginal Effect of Immigration Salience)
drop pipe where
restore

nbreg DEMIG_count l.DEMIG_count c.csaliency_avg##c.nomgdpgr polconiii lnpop lngdppc ln_migration sl_uem_totl_zs i.ccode i.year, cluster(ccode)

preserve
generate where = -0.5
generate pipe = "|"
reg DEMIG_count l.DEMIG_count c.csaliency_avg##c.nomgdpgr polconiii lnpop lngdppc ln_migration sl_uem_totl_zs i.ccode i.year, cluster(ccode)
keep if e(sample)
qui margins, dydx(csaliency_avg) at(nomgdpgr=(-9.5(1)11.5)) atmeans
marginsplot, level(90) recast(line) recastci(rline) ci1opts(lp(-) lc(black)) name(graph1, replace) addplot (scatter where nomgdpgr, xlabel(-9.5(2)11.5) ms(none) blcolor(gray) mlabel(pipe) mlabpos(0)) legend(off) scheme(plotplain) aspectratio(1) title("") xtitle(GDP Growth) ytitle(Marginal Effect of Immigration Salience) 
drop pipe where
restore
